#pragma once

#include "common.h"

#define MODE_6113	0
#define MODE_3195A	1

struct cic {
	u4 a;		// accum
	u4 x;
	u6 b;		// RAM pointer

	u10 pc;
	u10 pc_stack[4];

	u8 c;		// Carry flag
	u8 skip;

	u8 port[4];

	u8 *rom;	// 512bytes 6113, 768bytes on 3195A
	u4 ram[32];	// 32 nybbles

	u8 model;

	unsigned int ticks;
};

extern cic cpu;

void cic_run(unsigned int ticks, const u8* input_stream);

inline void pc_push() {
	cpu.pc_stack[3] = cpu.pc_stack[2];
	cpu.pc_stack[2] = cpu.pc_stack[1];
	cpu.pc_stack[1] = cpu.pc_stack[0];
	cpu.pc_stack[0] = cpu.pc;
}

inline void pc_pop() {
	cpu.pc = cpu.pc_stack[0];
	cpu.pc_stack[0] = cpu.pc_stack[1];
	cpu.pc_stack[1] = cpu.pc_stack[2];
	cpu.pc_stack[2] = cpu.pc_stack[3];
	//cpu.pc_stack[3] = 0;
}
